from musicService import musicService
import tkinter
from tkinter.filedialog import askopenfilenames


class playWindow:
    def __init__(self,service):
        self.ms = service

    def import_music(self, event):
        print('点击了导入按钮')
        files = askopenfilenames(filetypes=(["MP3 files", "*.mp3"], ['flac', '*.flac']))
        # print(files)
        self.ms.add_music(files)

    def delete_music(self, event):
        print('点击了删除按钮')

    def play_music(self, event):
        print('点击了播放按钮')

    def show_window(self):
        window = tkinter.Tk()
        # 添加按钮
        play_button = tkinter.Button(window, text='播放')
        import_button = tkinter.Button(window, text='导入')
        delete_button = tkinter.Button(window, text='删除')
        play_button.grid(row=0, column=0, padx=5, pady=5)
        import_button.grid(row=0, column=2, padx=5, pady=5)
        delete_button.grid(row=0, column=4, padx=5, pady=5)

        # 添加列表
        m_list = tkinter.Listbox()
        m_list.grid(row=2, column=0, columnspan=5, padx=5, pady=5)

        # 绑定事件
        play_button.bind('<ButtonRelease-1>', self.play_music)
        import_button.bind('<ButtonRelease-1>', self.import_music)
        delete_button.bind('<ButtonRelease-1>', self.delete_music)

        window.mainloop()


if __name__ == '__main__':
    # name = input('请输入用户名：')
    # password = input('请输入密码：')
    name = 'jinqiu'
    password = '123'

    sqlService = musicService()
    play = playWindow(sqlService)
    result = sqlService.login(name, password)
    if result:
        print('登录成功')
        play.show_window()
    else:
        print('用户名或密码错误')

"""
1.回顾导入的操作，调用类方法时：要使用类名().func()
"""
